﻿using HalconDotNet;
using vciplib0;
using Newtonsoft.Json;
using PCBase.UIControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.ComponentModel.Design;
using System.Windows.Forms;

namespace SECSParm
{

    public class PRM_WaferAOI
    {


        [Category("0.基本参数"), DisplayName("0.工单参数名"), Description("工单名称，由大小写字母，数字字符组成,不可使用符号")]
        //[EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor))]
        [ReadOnly(true)]
        public string PRM_Name { get; set; } //= "OCHAkkon_88";

        [Category("0.基本参数"), DisplayName("1.镜头倍率"), Description("检测镜头信息")]
        [ReadOnly(true)]
        public string PRM_LenInfo { get; set; } //= 200;

        [Category("0.基本参数"), DisplayName("2.Wafer类型"), Description("[重要参数] 按切割前后分类,影响算法")]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)) , TypeConverter(typeof(WaferTypeDefine)), Browsable(true)]
        public string PRM_WaferType { get; set; } = "1:切割前";   //OutputRotationDefine

        [Category("0.基本参数"), DisplayName("3.复判输出角度"), Description("[重要参数] 复判后导出tsk,txt旋转角度")]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(OutputRotationDefine)), Browsable(true)]
        public int PRM_OutputRotation { get; set; } = 0;   //OutputRotationDefine


        [Category("0.基本参数"), DisplayName("4.复判输出文件类型"), Description("[重要参数] 定义复判输出文件类型，txt,tsk")]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(OutputFilesDefine)), Browsable(true)]
        public string PRM_OutputFile { get; set; } = "3:txt,tsk";


        [Category("0.基本参数"), DisplayName("5.客户代码"), Browsable(true), Description("[重要参数] 产品客户代码")]
        public string PRM_CustomerNo { get; set; } = "";

        [Category("0.基本参数"), DisplayName("6.扫描图旋转角度"), Browsable(true), Description("0：0° | 1：90° | 2：-90° | 3：180°")]
        [ReadOnly(true)]
        public int PRM_WaferMapRotation { get; set; } = 0; 

        private int _scanWidthExtend = 550;
        [Category("0.基本参数"), DisplayName("7.扫描图宽度扩展"), Browsable(false), Description("扫描图宽度扩展, 单位um, 范围 550 - 1000um")]
        public int ScanWidthExtend
        {
            get
            {
                return _scanWidthExtend; 
            }
            set 
            {
                try
                {
                    if (value >= 550 && value <= 1000)
                    {
                        _scanWidthExtend = value;
                    }
                    else
                    {
                        _scanWidthExtend = 550;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("请输入正确格式!", "提示");
                }
                
            }
        }

        private int _scanHeightExtend = 10;
        [Category("0.基本参数"), DisplayName("7.扫描图高度扩展"), Browsable(true), Description("扫描图高度扩展, 单位um, 范围 10 - 1000um")]
        public int ScanHeightExtend
        {
            get
            {
                return _scanHeightExtend;
            }
            set
            {
                try
                {
                    if (value >= 10 && value <= 1000)
                    {
                        _scanHeightExtend = value;
                    }
                    else
                    {
                        _scanHeightExtend = 10;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("请输入正确格式!", "提示");
                }

            }
        }

        [Category("0.基本参数"), DisplayName("8. 动态模板"), Description("动态模板"), DefaultValue(true), Browsable(true)]
        public bool DynGolden { get; set; } = false;

        [Category("A.扫描程序集合"), DisplayName("扫描程序集合"), Description("扫描程序集合"), Browsable(false)]

        public Dictionary<int, PRM_Scan> Progs { get; set; } = new Dictionary<int, PRM_Scan>();

        [Category("A.Wafer Die类型编辑功能"), DisplayName("Wafer Die类型编辑功能是否启用"), Description("True:启用，False:禁用. 决定Die使用哪个程序扫描"), Browsable(true)]
        public bool PRM_DieTypeEditEnable { get; set; } = false;

        [Category("A.Wafer Die类型集合"), DisplayName("Wafer Die类型集合"), Description("指示Die使用哪个Prog程序扫描处理"), Browsable(false)]
        public int[,] PRM_DieTypes { get; set; } = null;

        public PRM_WaferAOI()
        {
            PRM_Name = "PName1";
        }
    }

    //扫描程序
    public class PRM_Scan
    {

        [Browsable(false)]
        public int ProgID { get; set; } = 0;


        [Category("0.基本参数"), DisplayName("0.检测程序描述"), Description("自定义检测程序描述信息,以便后续使用")]
        public string PRM_Remark { get; set; } = "BaseLayer";

        [Category("0.基本参数"), DisplayName("1.程序是否启用"), Description("检测程序是否启用")]
        public bool ProgEnable { get; set; } = true;

        [Category("0.基本参数"), DisplayName("2.Golden模式"), Description("[重要参数] By Wafer,By Lot,By Device")]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(GoldenMakeDefine)), Browsable(false)]
        public string PRM_GoldenCreate { get; set; } = "1:By Wafer";   //OutputRotationDefine

        [Category("0.基本参数"), DisplayName("3.镜头倍率"), Description("检测镜头信息")]
        public string PRM_LenInfo { get; set; } //= 200;

        [Category("0.基本参数"), DisplayName("4. 动态模板"), Description("动态模板"), DefaultValue(true), Browsable(true)]
        public bool DynGolden { get; set; } = false;


        [CategoryAttribute("0.基本参数"), DisplayName("4.检测算法[明]"), Description("检测算法 1.简易模式,2.标准模式,3.精细模式  ,默认值 Standard"), Browsable(true)]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(DetectMethod))]
        public string DetectMethod_B { get; set; } = "1.Simple";


        [CategoryAttribute("0.基本参数"), DisplayName("4.检测算法[暗]"), Description("检测算法 1.简易模式,2.标准模式,3.精细模式  ,默认值 Standard"), Browsable(true)]
        [EditorAttribute(typeof(CommonInputEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(DetectMethod))]
        public string DetectMethod_D { get; set; } = "2.Standard";

        [Category("1.光源参数"), DisplayName("a.BF亮度"), Browsable(true), Description("BF亮度 0-255")]
        public int AOILightBF { get; set; } = 32;

        [Category("1.光源参数"), DisplayName("b.BF滤镜"), Browsable(false), Description("BF滤镜")]
        public int AOIBF_Filter { get; set; } = 0;

        [Category("1.光源参数"), DisplayName("c.DF亮度"), Browsable(true), Description("DF亮度 0-255")]
        public int AOILightDF { get; set; } = 0;

        [Category("1.光源参数"), DisplayName("d.DF滤镜"), Browsable(false), Description("DF滤镜")]
        public int AOIDF_Filter { get; set; } = 0;

        //[EditorAttribute(typeof(BinaryEditor), typeof(System.Drawing.Design.UITypeEditor)), TypeConverter(typeof(GoldenMakeDefine))]
        [Editor(typeof(BinaryEditor), typeof(System.Drawing.Design.UITypeEditor))]

        [Category("2.功能参数"), DisplayName("段选择扫描"), Browsable(false), Description("段选择扫描")]
        public uint SegmentScalFlag { get; set; } = 0xFFFFFFFF;


        [Category("2.功能参数"), DisplayName("扫描高度偏移"), Browsable(true), Description("扫描高度，相对底部Z轴偏移。单位(um)")]
        public double HeightOffset { get; set; } = 0;




        [Category("9.检测参数集合"), DisplayName("检测参数集合"), Description("检测参数集合"), Browsable(false)]
        public Dictionary<int, PRM_SegFrameInsp> AOIParas { get; set; } = new Dictionary<int, PRM_SegFrameInsp>();//
    }




    /// <summary>
    /// 默认参数，可作为所有检测设定的参考 
    /// </summary>
    public class PRM_Default
    {
        [CategoryAttribute("2.检测参数 Bright"), DisplayName("a.最小Defect面积 [Bright]"), Description("Bright 最小区域面积，单位um. 默认值: 50"), Browsable(true)]
        public Double Bright_MinDefectArea { get; set; } = 50.0;

        [CategoryAttribute("2.检测参数 Bright"), DisplayName("d.Defect灰阶差阈值 [Bright]"), Description("Bright Defect灰阶差阈值 设置范围[20 - 255] ,默认值 35"), Browsable(true)]
        public Double Bright_MinContrastDalta { get; set; } = 35;

        [CategoryAttribute("3.检测参数 Dark"), DisplayName("a.最小Defect面积 [Dark]"), Description("Dark 最小区域面积，单位um. 默认值: 50"), Browsable(true)]
        public Double Dark_MinDefectArea { get; set; } = 50.0;


        [CategoryAttribute("3.检测参数 Dark"), DisplayName("d.Defect灰阶差阈值 [Dark]"), Description("Dark Defect灰阶差阈值 设置范围[20 - 255] ,默认值 35"), Browsable(true)]
        public Double Dark_MinContrastDalta { get; set; } = 35;

    }

}
